/*-------------------------------------------------------------------------------
* file:     app_touchpad.h
* brief:    application
* copyright Copyright (C) 2020-2022 @ NanoIC
* Date:     2023-09-06
* Version:  V1.00
* Author:   
*-------------------------------------------------------------------------------*/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __APP_TOUCHPAD_H__
#define __APP_TOUCHPAD_H__
/* Includes ------------------------------------------------------------------*/
// #include "one_wire_bus_app.h"
#include "app_upgrade.h"
#include "app_key.h" 
#include "common.h" 
#include "sys_console.h"
#include "app_cfg.h"

/* Private macro-----------------------------------------------------------*/
#define TOUCHPAD_I2CADDR_GTM1B00                    (0x2C<<1)    //   (0x2C << 1)//   
#define TOUCHPAD_I2CADDR_GTM1B00_ROM                (0x5D << 1)
#define TOUCHPAD_HUI_DING_VID                       0x27C6
#define TOUCHPAD_HUI_DING_PID                       0x01E0
#define TP_IIC_PING_INT                             PA00
#define PINMASK_TP_IIC_INT                          0
#define TOUCHPAD_I2CADDR_ZINITIX           (0x20<<1) 



#define U16_HI(a)    (((a) >> 8) & 0xFF)
#define U16_LO(a)    ((a) & 0xFF)

// Logical Size
#define TOUCHPAD_X_SIZE                           3684//2560
#define TOUCHPAD_Y_SIZE                           2176//1600

// Physical Size
#define PHY_X                            	401//(u16)((float)401*0.7)//401*2// 1020
#define PHY_Y                             	275//(u16)((float)275*0.7)//*2//600


/* --------------------------TP OTA---------------------------------*/
#define CFG_VERSION_ADDR			0x60DC
/* --------------------------TP OTA---------------------------------*/
extern volatile bool tp_sleep_up_enable_flag;
extern uint8_t TP_version;
extern uint32_t TP_ID;

#define IIC_TX_BUF_LENGTH                   64
#define IIC_RX_BUF_LENGTH                   72

typedef struct __TouchPad_Desc_Typedef
{
    uint16_t report_desc_len;
    uint16_t report_reg;
    uint16_t input_reg;
    uint16_t input_max_len;
    uint16_t output_reg;
    uint16_t output_max_len;
    uint16_t command_reg;
    uint16_t data_reg;
    uint16_t vid;
    uint16_t pid;
    uint16_t version;
}TouchPadDesc_Typedef;

/* Private function--------------------------------------------------------*/

void app_tp_init(void);

void app_touch_pad_process(void);

bool app_touch_pad_prevent_error_alg(uint8_t * in_touch_buf, uint8_t finger_r,uint8_t hand_number);

void app_touch_pad_lowpower_io_set(bool on);

void app_touch_pad_doze_io_set(bool on);

void app_tp_io_set_init(void);

bool app_touch_pad_big_hand_alg(uint8_t * in_touch_buf, uint8_t f_finger, uint8_t big_hand_num);

bool app_touch_pad_big_hand_falg(uint8_t * in_touch_buf, uint8_t f_finger);


extern uint8_t first_touch_flag_f1, first_touch_flag_f2;
extern uint8_t touch_idle_flag;
extern volatile uint8_t touch_tick;
#endif



